package com.boot.mgt.controller.accident

import com.boot.core.result.ResultTo
import com.boot.mgt.service.StatisticsService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.format.annotation.DateTimeFormat
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import java.util.*

/**
 * 统计接口,数据源为Oracle
 * @author kawins
 * createTime 2018-12-09 17:09
 */
@RestController
@RequestMapping("/api/statistics")
class StatisticsController {

    @Autowired
    private lateinit var statisticsService: StatisticsService

    /**
     * 一般事故
     */
    @GetMapping("/accident")
    fun generalAccident(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") start_time: Date,
                        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") end_time: Date,
                        @RequestParam(required = false, defaultValue = "0") deathStart: Int,
                        @RequestParam(required = false, defaultValue = "2") deathEnd: Int): ResultTo {
        return statisticsService.accident(start_time, end_time, deathStart, deathEnd)
    }

    /**
     * 一般事故
     */
    @GetMapping("/accidentRpc")
    fun generalAccidentRpc(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") start_time: Date,
                        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") end_time: Date,
                        @RequestParam(required = false, defaultValue = "0") deathStart: Int,
                        @RequestParam(required = false, defaultValue = "2") deathEnd: Int,
                        @RequestParam(required = false, defaultValue = "1") police_level: Int
    ): ResultTo {
        return statisticsService.accidentRpc(start_time, end_time, deathStart, deathEnd, police_level)
    }

    /**
     * 较大事故
     */
    @GetMapping("/majorAccident")
    fun majorAccident(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") start_time: Date,
                      @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") end_time: Date): ResultTo {
        return statisticsService.accident(start_time, end_time, 3, 9)
    }

    /**
     * 重大事故
     */
    @GetMapping("/bestMajorAccident")
    fun bestMajorAccident(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") start_time: Date,
                          @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") end_time: Date): ResultTo {
        return statisticsService.accident(start_time, end_time, 10, 29)
    }

    /**
     * 特大事故
     */
    @GetMapping("/seriousAccident")
    fun seriousAccident(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") start_time: Date,
                        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") end_time: Date): ResultTo {
        return statisticsService.accident(start_time, end_time, 30, 100)
    }

}